﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RESTAURANT
{
    public partial class frmSignInNoCard : Form
    {
        private const string user = "admin";
        private const string pass = "dhatram";

        public frmSignInNoCard()
        {
            InitializeComponent();
            btnSignIn.Text = "Đăng Nhập";
            this.Text = "Đăng nhập tài khoản";
            lblStatus.ForeColor = Color.White;
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            InOutPartAccount();           
        }

        private void InOutPartAccount()
        {
            try
            {
                string user = txtUserName.Text.ToLower().Trim();
                string pass = Encrypt.Encrypte(txtPass.Text);
                string sql = string.Format(@"Select * from employee where deleted='false' and employeeuserName=N'{0}' and employeePassword=N'{1}'", user, pass);
                DataTable dt = UsingSql.GetQuery(sql);
                if (dt.Rows.Count >= 1)
                {
                    UsingSql.Admin = dt.Rows[0]["RoleID"].ToString();
                    UsingSql.EmployeeID = dt.Rows[0]["employeeID"].ToString();
                    UsingSql.EmployeeName = dt.Rows[0]["employeeFirstName"].ToString().Trim() + " " + dt.Rows[0]["employeeLastName"].ToString();
                    this.Visible = false;
                    (new frmMainForm()).ShowDialog();
                    Application.Exit();
                }
            }
            catch (Exception)
            {
            }
        }

        private void btnDangNhapThe_Click(object sender, EventArgs e)
        {
            InOutPartAccount();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtMatKhau_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Escape")
            {
                this.Close();
            }
            if (e.KeyCode.ToString() == "Return")
            {
                if (txtUserName.Text != "" && txtPass.Text !="")
                {
                    InOutPartAccount();
                    txtUserName.Focus();
                }
                else
                {
                    MessageBox.Show("Vui lòng điền đủ thông tin");
                    txtUserName.Focus();
                    txtUserName.Text = "";
                    txtPass.Text = "";
                }
            }
        }

        private void txtUserName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Return")
            {
                if (txtUserName.Text != "" && txtPass.Text != "")
                {
                    InOutPartAccount();
                    txtUserName.Focus();
                }
                else
                {
                    MessageBox.Show("Vui lòng điền đủ thông tin");
                    txtUserName.Focus();
                    txtUserName.Text = "";
                    txtPass.Text = "";
                }
            }
            else if (e.KeyCode.ToString() == "Escape")
            {
                this.Close();
            }
        }

        private void frmSignInNoCard_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }

        private void frmSignInNoCard_Load(object sender, EventArgs e)
        {
            txtPass.PasswordChar = '*';
        }
    }
}
